package flexo.graphic;

import java.util.HashMap;

import flexo.common.ResourcePool;


/**
 * Used to store all the shaders in the engine. There are some built-in shaders:
 * 
 * 		default: applies red color to all the geometry, just for testing purposes.
 * 
 * @author Miguel
 *
 */
public class ShaderPool extends ResourcePool
{
	protected java.util.HashMap<String, String> builtInShaders;
	
	public ShaderPool()
	{
		builtInShaders = new HashMap<String, String>();
		
		builtInShaders.put("default", "media/shaders/default");
		builtInShaders.put("billboard", "media/shaders/billboard");
		builtInShaders.put("textureRepeat", "media/shaders/textureRepeat");
		builtInShaders.put("outline", "media/shaders/outline");
		builtInShaders.put("particles", "media/shaders/particles");
		builtInShaders.put("oneColor", "media/shaders/oneColor");
		builtInShaders.put("oneColorBillboard", "media/shaders/oneColorBillboard");
	}
	
	public Shader get(String resourceName)
	{
		if (builtInShaders.containsKey(resourceName))
		{
			resourceName = builtInShaders.get(resourceName);
		}
		
		Shader shader = (Shader)super.get(resourceName);
		if (shader == null)
		{
			flexo.file.FileSystem fs = (flexo.file.FileSystem)flexo.Kernel.getSystem(flexo.file.FileSystem.ID);
			String vertexShaderFile = fs.getFullPath(resourceName + ".vs");
			String fragmentShaderFile = fs.getFullPath(resourceName + ".fs");
			shader = new Shader(vertexShaderFile, fragmentShaderFile);
			String resFullPath = vertexShaderFile.substring(0, vertexShaderFile.length()-3);
			add(resFullPath, shader);
		}
		return shader;
	}
}
